function encodeToHex(str){
    var r=[];
    var e=str.length;
    var c=0;
    var h;
    while(c<e){
        h=str.charCodeAt(c++);
	r.push(h);
    }
    return r;
}

function decodeHex(hex){
    function decoder(ch){
	if (32<ch&&ch<127){
	    return (String.fromCharCode(ch));	    
	} else {
	    return ".";
	}
    };
    return (hex.map(decoder));
}

function dumpCode(rom)
{
    var code = document.getElementById('rom-cont');
    var hex = encodeToHex(rom);
    var len = hex.length;
    var i=0;
    var hex_list = [];
    var res=[];
    while(i<len) {
	if(i%8==0&&i>0) {
	    hex_list.push(res);
	    res=[];
	}	
	res.push(hex[i]);
	i++;
    }
    hex_list.push(res);
    
    function dump(frag) {
	var dec = decodeHex(frag);
	var hex = frag.map(
	    function(c)
	    {
		var res=c.toString(16);
		if(res.length<2){res="0"+res};
		return res});
	return("<tr><td>"+(hex.join(" "))+"</td><td>"+(dec.join(""))+"</td></tr>");
    }
    
    var output = "<table>"+(hex_list.map(dump)).join("")+"</table>";
    code.innerHTML=output;
    fleXenv.updateScrollBars();    
}

function dumpRomInfo(Rom)
{
    function mkTD(name,val)
    {
	return "<tr><td>"+name+"</td><td>"+val+"</td></tr>";
    };

    var info = "<table>" +
	mkTD("Rom Count:",Rom.romCount) +
	mkTD("VRom Count:",Rom.vromCount) +
	mkTD("Mapper Type:",Rom.mapper) +
	"</table>";
    
    var div = document.getElementById("rominfo-cont");
    div.innerHTML = info;
};

function dumpMemoryMap()
{
    
}

function arraycopy (src,src_addr,dst,dst_addr,len)
{
    var i;
    for(i=0;i<len;i++)
    {
	dst[dst_addr+i]=src[src_addr+i];
    };
};